#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<assert.h>
using namespace std;


  struct TreeNode {
      int val;
      struct TreeNode *left;
     struct TreeNode *right;
 };


int TreeSize(struct TreeNode* root)
{
    if (root == NULL)
        return 0;
    else
        return 1 + TreeSize(root->left) + TreeSize(root->right);
}

void _postorderTraversal(struct TreeNode* root, int* arr, int* pi)
{
    if (root == NULL)
        return;
    _postorderTraversal(root->left, arr, pi);
    _postorderTraversal(root->right, arr, pi);
    arr[(*pi)] = root->val;
    (*pi)++;
}

int* postorderTraversal(struct TreeNode* root, int* returnSize)
{
    int size = TreeSize(root);
    int* arr = (int*)malloc(sizeof(int) * size);
    *returnSize = size;
    int i = 0;
    _postorderTraversal(root, arr, &i);
    return arr;
}